package base_demo.test2;

public class Myrun implements Runnable{
    int ticket = 0;
    @Override
    public void run() {
        while(true){
            if (extracted()) break;
        }
    }

    private synchronized boolean extracted() {
        synchronized(Myrun.class){
            if(ticket == 100){
                return true;
            } else {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                ticket++;
                System.out.println(Thread.currentThread().getName() + "正在卖第" + ticket + "票!!!");
            }
        }
        return false;
    }
}
